/*************************************************************************
> File Name: send_multicast.c
> Author: hzy
> Created Time: 2023-09-20 11:39:32
> Description:
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h> /* See NOTES */
#include <sys/socket.h>
#include <arpa/inet.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(int argc, char const *argv[])
{
    // 创建套接字
    int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
    if (sockfd < 0)
    {
        perror("socket");
        return -1;
    }

    // 设置多播地址
    struct sockaddr_in send_addr;
    send_addr.sin_family = AF_INET;
    send_addr.sin_port = htons(10086);
    send_addr.sin_addr.s_addr = inet_addr("224.0.0.1");

    for (int i = 0; i < 3; i++)
    {
        int ret1 = sendto(sockfd,
                          "zzb is beautiful",
                          sizeof("zzb is beautiful"),
                          0,
                          (struct sockaddr *)&send_addr,
                          sizeof(send_addr));
        if (ret1 < 0)
        {
            perror("sendto");
            return -1;
        }
    }

    return 0;
}